package com.cn.utils;

import java.security.MessageDigest;

public class token {
    public static boolean decrypt(Long time,String id,String token){
        String code = encryption(time,id);
        if(token.equals(code)){
            return true;
        }
        return false;
    }

    public static String  encryption(Long time,String id) {
        String secretKey = "2fd312e6-9239-4f95-82f6-fe3191e10dae";
        String code =id + secretKey + time;
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(code.getBytes("UTF8"));
            byte s[] = m.digest();
            String result = "";
            for (int i = 0; i < s.length; i++) {
                result += Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6);
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    public static void main(String[] args) {
        //Long t=System.currentTimeMillis();
      Long  t= 1566891209290L;
       String code = encryption(t,"1111111");
       System.out.println(t);
       System.out.println(code);
       boolean b =decrypt(t,"111111","feb163b94ea8e633a32580d600dff7ce");
        System.out.println(b);
    }
}
